package me.bemayor.components.twin.items;

import me.bemayor.api.common.ItemStackUtils;
import me.bemayor.api.customitem.CustomItemStack;
import me.bemayor.components.transition.items.HeadTexture;
import me.bemayor.components.twin.TwinUsage;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ShapedRecipe;

public class TwinMaker extends CustomItemStack {
    public TwinMaker() {
        super("TWIN_MAKER",
                HeadTexture.TWIN_MAKER.getTexture(),
                "&6孪生制造机",
                "&a&o对孪生制造机附近的箱子制造孪生容器", "&f用来合成便携孪生箱","", "&e放置在箱子的附近并右击制造机&7进行使用");

        this.setUseAction(event -> {
            Player p = event.getPlayer();
            Location l = event.getClickedBlock().getLocation();
            Location chestLocation=TwinUsage.findChest(l);
            if(chestLocation!=null){
                openTwinCore(p,chestLocation);
                p.playSound(p.getEyeLocation(), Sound.BLOCK_SHULKER_BOX_OPEN, 1F, 0.6F);
            }else{
                p.sendMessage("§c孪生制造机附近没有找到箱子，请重新在附近放上箱子！");
            }
        });

        this.setRecipe(new ShapedRecipe(ItemStackUtils.keyBuilder(this.getId()),this.getCloneItemStack())
                .shape("axa", "byb", " z ")
                .setIngredient('x', Material.TRIPWIRE_HOOK)
                .setIngredient('y', Material.HOPPER)
                .setIngredient('z', Material.ENDER_EYE)
                .setIngredient('a', Material.LIGHTNING_ROD)
                .setIngredient('b', Material.OBSERVER)
        );

    }

    public void openTwinCore(Player player, Location chestLocation) {
        TwinMakerGui tcGui = new TwinMakerGui();
        tcGui.open(player, chestLocation);
    }

}
